<template>
    <div class="box">
		<input type="text" v-model="title" @keyup.enter="add" placeholder="按按回车">
	</div>
</template>

<script>

    export default {
		name:'MyHeader',
		data() {
			return {
				title:'',
			}
		},
		methods: {
			add(){
				if(this.title!=''){
					let thing = {id:Math.random(),title:this.title,done:false}
					this.$emit('addThing',thing)
					this.title = ''
				}else{
					alert('添加事项不能为空!')
				}
				//将用户输入包装为事件对象
				
			}
		},
	}
</script>

<style scoped>
	
</style>